import { Body, Controller, Get, Param, ParseIntPipe, Post, Query } from '@nestjs/common'
import { ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator'
import { AsrQueryDto } from '../dto/asr-query.dto'
import { CreateAsrTaskDto } from '../dto/create-asr-task.dto'
import { AsrTaskEntity } from '../entities/asr-task.entity'
import { AsrTaskPaginationResult, AsrTaskResult } from '../interfaces/asr.interface'
import { AsrService } from '../services/asr.service'

@ApiTags('Common - ASR语音识别服务')
@ApiSecurityAuth()
@Controller('common/asr')
export class AsrController {
  constructor(private readonly asrService: AsrService) {}

  @ApiOperation({ summary: '创建ASR语音识别任务' })
  @ApiResponse({ status: 200, description: '创建成功', type: Object })
  @Post('task')
  async createAsrTask(@Body() createAsrTaskDto: CreateAsrTaskDto): Promise<AsrTaskResult> {
    return this.asrService.createTencentAsrTask(createAsrTaskDto)
  }

  @ApiOperation({ summary: '查询ASR任务列表' })
  @ApiResponse({ status: 200, description: '查询成功', type: Object })
  @Get('tasks')
  async findAsrTasks(@Query() query: AsrQueryDto): Promise<AsrTaskPaginationResult> {
    return this.asrService.findAll(query)
  }

  @ApiOperation({ summary: '根据ID查询ASR任务' })
  @ApiParam({ name: 'id', description: 'ASR任务ID' })
  @ApiResponse({ status: 200, description: '查询成功', type: AsrTaskEntity })
  @Get('task/:id')
  async findAsrTaskById(@Param('id', ParseIntPipe) id: number): Promise<AsrTaskEntity> {
    return this.asrService.findById(id)
  }

  @ApiOperation({ summary: '根据腾讯云任务ID查询ASR任务' })
  @ApiParam({ name: 'taskId', description: '腾讯云ASR任务ID' })
  @ApiResponse({ status: 200, description: '查询成功', type: AsrTaskEntity })
  @Get('task/by-task-id/:taskId')
  async findAsrTaskByTaskId(@Param('taskId') taskId: string): Promise<AsrTaskEntity> {
    return this.asrService.findByTaskId(taskId)
  }
}
